/*
Copyright (c) 2008-2009, Attigo (Hong Kong) Limited
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of Attigo (Hong Kong) Limited nor the names of its
      contributors may be used to endorse or promote products derived from this
      software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.attigohk.labs.smugjcu;

import java.io.File;

/**
 * The SmugJCU application class.
 */
public class SmugJCU {

    public static String VERSION = "1.1";
    public SmugJCU(File file, String username, String password, int albumId,
            boolean preventDuplicates) {
        new Processor(file, username, password, albumId, preventDuplicates);
    }

    /**
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            if (args.length == 1 && args[0].equals("-license")) {
                showLicense();
                System.exit(0);
            } else if (args.length != 4) {
                showUsageInfo();
                System.exit(1);
            }

            String username = args[0];
            String password = args[1];
            int albumId = Integer.decode(args[2]);
            File file = new File(args[3]);

            new SmugJCU(file, username, password, albumId, true);
        } catch (java.lang.OutOfMemoryError err) {
            System.out.println("You ran out of memory! Try increasing the " +
                    "java heap size to 1 gigabyte by adding the" +
                    " \"-Xmx1024m\" flag to the command line.");
            System.exit(1);
        } catch (Exception e) {
            showUsageInfo();
            System.exit(1);
        }
    }

// TODO add support for disabling duplicate scanning from the command line
    private static void showUsageInfo() {
        System.out.println("SmugJCU v" + VERSION + " - Java Commandline Uploader for SmugMug");
        System.out.println("Copyright (C) 2008-2009 - Attigo (Hong Kong) Limited");
        System.out.println("Written by SmugMug user larrysalibra");
        System.out.println("");
        System.out.println("For license info run: java -jar smugjcu.jar -license");
        System.out.println("");
        System.out.println("USAGE: java -jar smugjcu.jar" +
                " <username> <password> <albumid> <file/dir>");
        System.out.println("Uploads a file or all of the files in a" +
                " directory (recursively)");
        System.out.println("to the SmugMug album specified.");
    }

    private static void showLicense() {
        System.out.println("Copyright (c) 2008-2009 Attigo (Hong Kong) Limited");
        System.out.println("All rights reserved.");
        System.out.println("Written by SmugMug user larrysalibra");
        System.out.println("");
        System.out.println("Redistribution and use in source and binary forms, with or without");
        System.out.println("modification, are permitted provided that the following conditions are met:");
        System.out.println("Redistributions of source code must retain the above copyright");
        System.out.println("notice, this list of conditions and the following disclaimer.");
        System.out.println("Redistributions in binary form must reproduce the above copyright");
        System.out.println("notice, this list of conditions and the following disclaimer in the");
        System.out.println("documentation and/or other materials provided with the distribution.");
        System.out.println("Neither the name of the company nor the");
        System.out.println("names of its contributors may be used to endorse or promote products");
        System.out.println("derived from this software without specific prior written permission.");
        System.out.println("");
        System.out.println(" THIS SOFTWARE IS PROVIDED BY Attigo (Hong Kong) Limited ''AS IS'' AND ANY");
        System.out.println(" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED");
        System.out.println(" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE");
        System.out.println(" DISCLAIMED. IN NO EVENT SHALL Attigo (Hong Kong) Limited BE LIABLE FOR ANY");
        System.out.println(" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES");
        System.out.println(" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;");
        System.out.println(" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND");
        System.out.println(" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT");
        System.out.println(" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS");
        System.out.println(" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.");

    }
}
